package com.ruantu.clothing.controller;

import com.ruantu.clothing.dao.ChuKuDao;
import com.ruantu.clothing.entity.JsonResponseMessage;
import com.ruantu.clothing.service.ChuKuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * Created by Administrator on 2018/8/19 0019.
 */
@Controller
@RequestMapping("/pic")
public class PicController {
    @Autowired
    private ChuKuService ckService;

    @RequestMapping(value = "/upfile")
    @ResponseBody
    public JsonResponseMessage upfile(MultipartFile upfile, HttpSession session,String chukuId) {

       JsonResponseMessage msg=new JsonResponseMessage();

        try {
               ckService.addPicService(chukuId,upfile,session);
              msg.setCode(200);
              msg.setMsg("添加成功!");
        }catch (Exception e){
            msg.setCode(400);
            msg.setMsg("添加失败!");
            e.printStackTrace();
        }
        return msg;// 返回图片url给ajax
    }


}
